﻿//创建人：Wangjh
//日期：2021-12-15
//描述：热表开卡页面

var page = {
    pagetotal: 0,
    pageSize: 5,
    pageNumber: 1,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ReBiaoConainer/RbContainerStartHandler.ashx",
    rbTypeAndWorkcenter://用户指定的热表批次类型和工区的映射关系
    {
      1:"热处理",//热处理
      2:"电镀酸洗",//电镀酸洗
      3:"涂装",  
    },
    //初始化页面
    init: function () {
        page.bind();
        addClearBtnToDatebox();
        $("#divChildContainer").hide();
        //后台请求，初始化数据
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: true,
            data: { action: "intiPageData" },
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                //prompt("", data);
                var result = JSON.parse(data);
                if (result.Result) {
                    var returnData = result.ReturnData;
                    $("#gdMainContainer").datagrid('loadData', { rows: returnData.MainContainer });
                    $("#gdSubContainer").datagrid('loadData', { rows: returnData.SubContainer });
                    //子序号列表 add by zhangrj 2022-10-27
                    if (returnData.MainContainer[0].CONTAINERTYPE==="3") {
                        $("#divChildContainer").show();
                        $("#gdChildContainer").datagrid('loadData', { rows: returnData.ChildContainer });
                    }
                    //子工艺
                    $("#txtSubWorkflowInfo").textbox('setValue', returnData.SubWorkflowId);
                    $("#txtSubWorkflowInfo").textbox('setText', returnData.SubWorkflowInfo);
                    //子件号
                    if (isNullOrWhiteSpaceStr(returnData.SubProductInfo)) {
                        $("#hdSubProductInfo").val(returnData.MainContainer[0].PRODUCTNAME + ":" + returnData.MainContainer[0].PRODUCTREV);
                    } else {
                        $("#hdSubProductInfo").val(returnData.SubProductInfo);
                    } 
                    //子工艺最新版本
                    $("#hdNewestSubWorkflowRev").val(returnData.NewestSubWorkflowRev);
                    //工区 
                    $("#dllWorkCenter").combobox('loadData', returnData.WorkCenter);

                    //转工序
                    $("#ddlShipStep").combobox('loadData', returnData.ShipStepDt);
                    //子批次前部分
                    var prefix = "";
                    prefix = $("#hdSubProductInfo").val().split(':')[0] + "/"
                    $("#txtProductPrefix").textbox('setValue', prefix);
                    $("#txtProductPrefix").parent().attr("title",prefix);
                    //数量 
                    if (returnData.MainContainer[0].CONTAINERTYPE == "7") {
                        $("#txtQty").numberbox('setValue', returnData.MainContainer.length);
                    } else {
                        $("#txtQty").numberbox('setValue', returnData.MainContainer[0].QTY);
                    }
                    //默认选择工区，默认时间信息
                    if (!isNullOrWhiteSpaceStr(returnData.EstimatedCompleteDate)) {
                        $("#txtEndDate").datebox('setValue', formatDate(returnData.EstimatedCompleteDate));
                    }
                    if (!isNullOrWhiteSpaceStr(returnData.ToWorkcenterID)) {
                        $("#dllWorkCenter").combobox('select', returnData.ToWorkcenterID);
                        //默认工区后，再默认到类型
                        var rbTypeValue="";
                        for(var item in page.rbTypeAndWorkcenter){
                            if(page.rbTypeAndWorkcenter[item]==$("#dllWorkCenter").combobox("getText")){
                                rbTypeValue=item;
                            }
                        }
                        if(rbTypeValue!=""){
                            $("#ddlRbType").combobox('select', rbTypeValue);
                        }
                    }
                     $("#txtStartDate").datebox('setValue',returnData.StepPlannedStartDate);
//                    var now = new Date();
//                    $("#txtStartDate").datebox('setValue', now.getFullYear() + "-" + now.getMonth() + "-" + now.getDate()); //开始日期默认为今天

                } else {
                    displayMessage(result.Message, false);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                alert(XMLHttpRequest.responseText);
            }
        });
        //
    },
    //页面事件绑定
    bind: function () {
        //主查询结果加载
        $("#gdMainContainer").datagrid({
            onLoadSuccess: function (data) {

            },
            onClickRow: function (index, rowData) {
                //alert('clickRow');
            },
            onCheck: function (index, rowData) {

            },
            onUncheck: function (index, rowData) {

            },
            onCheckAll: function (index, rowData) {

            },
            onUncheckAll: function (index, rowData) {

            },
            onSelect: function (index, rowData) {
                //alert('onSelect');
            },
            columns: [[
            //                 { field: 'ck', title: '选择', checkbox: true },
                 {field: 'MFGORDERNAME', title: '订单号', width: 120 },
                 { field: 'CONTAINERNAME', title: '主批次', width: 130 },
		         { field: 'PRODUCTDESCRIPTION', title: '零件名称', width: 130 },
                 { field: 'QTY', title: '数量', width: 40 },
                 { field: 'WORKFLOWSTEPNAME', title: '当前工序', width: 180 },
                 { field: 'CONTAINERTYPENAME', title: '批次类型', width: 100 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始', width: 100, formatter: function (value) {
                     if (value != null)
                         return value.replace("T", "").replace("00:00:00", "").replace("0:00:00", "");
                 }
                 },
                 { field: 'PLANNEDCOMPLETIONDATE', title: '计划完成', width: 100, formatter: function (value) {
                     if (value != null)
                         return value.replace("T", "").replace("00:00:00", "").replace("0:00:00", "");
                 }
                 },
		         { field: 'WORKFLOWID', title: '工艺', hidden: true },
                 { field: 'TOGETHERFLAG', title: '批次顺序', hidden: true },
                 { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true },
                 { field: 'CONTAINERTYPE', title: '流水卡类型', hidden: true },
                 { field: 'PRODUCTID', title: '零件图号ID', hidden: true },
                 { field: 'PRODUCTNAME', title: '零件图号', hidden: true },
                 { field: 'PRODUCTREV', title: '零件版本', hidden: true },
                 { field: 'WORKFLOWSTEPID', title: '工序ID', hidden: true },
                 { field: 'WORKFLOWSTEPSEQUENCE', title: 'workflowstepsequence', hidden: true }

	           ]]
        });
         //子序号列表
        $("#gdChildContainer").datagrid({
            columns: [[
                { field: 'ck', title: '选择', checkbox: true },
                { field: 'CONTAINERNAME', title: '子序号批次', width: 200 },
                { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true }

	        ]]
        });
        //已创建子卡信息
        $("#gdSubContainer").datagrid({
            onLoadSuccess: function (data) {

            },
            columns: [[
                { field: 'CONTAINERNAME', title: '批次', width: 200, formatter: function (value, row, index) {
                         return "<span contentEditable='true'>" + value + "</span>";
                 } 
                },
                { field: 'QTY', title: '数量', width: 40 },
                { field: 'WORKFLOWSTEPNAME', title: '主卡工序', width: 150 },
                { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true }

	        ]]
        });
        //子卡批次信息
        $("#gdSubContainer2").datagrid({
            onLoadSuccess: function (data) {

            },
            columns: [[
                { field: 'MFGORDERNAME', title: '订单号', width: 120, hidden: true },
                { field: 'CONTAINERNAME', title: '批次', width: 180 },
		        { field: 'PRODUCTDESCRIPTION', title: '零件名称', width: 130, hidden: true },
                { field: 'QTY', title: '数量', width: 40 },
                { field: 'CONTAINERTYPENAME', title: '批次类型', width: 100 },
                { field: 'WORKFLOWINFO', title: '工艺', width: 150 },
                { field: 'PLANNEDSTARTDATE', title: '计划开始', width: 100, formatter: function (value) {
                    return value.replace("T", "").replace("00:00:00", "").replace("0:00:00", "");
                }
                },
                { field: 'PLANNEDCOMPLETIONDATE', title: '计划完成', width: 100, formatter: function (value) {
                    return value.replace("T", "").replace("00:00:00", "").replace("0:00:00", "");
                }
                },
                { field: 'CONTAINERTYPE', title: '批次类型', hidden: true }
                , { field: 'TOGATHERFLAG', title: 'TOGATHERFLAG', hidden: true }

	        ]]
        });
        //开始时间
        $('#txtStartDate').datebox('calendar').calendar({
            validator: function (date) {
                var now = new Date();
                var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                return d1 <= date;
            }
        });
        //结束时间
        $('#txtEndDate').datebox('calendar').calendar({
            validator: function (date) {
                var now = new Date();
                var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                return d1 <= date;
            }
        });
        //选择热表批次类型
        $("#ddlRbType").combobox({
            onChange: function (n,o) {
                page.getContainerNo();
                //默认工区
                var workcenters=$("#dllWorkCenter").combobox('getData');
                var userCustomWC=page.rbTypeAndWorkcenter[n];//用户自定义批次类型对应的工区
                var selectItem=workcenters.filter(function(e){
                   return e.WORKCENTERNAME.indexOf(userCustomWC)!=-1;
                });
                if(selectItem.length>0)
                {
                    $("#dllWorkCenter").combobox('select',selectItem[0].WORKCENTERID);
                }
            }
        });
        $("#ddlShipStep").combobox({
         onChange: function (n,o) {
         page.getRBChildWorkflow();
         }
        });
        //预览批次按钮
        //        $('#btnSearch').on("click", function () {
        //            page.previewSubContainer();
        //        });
        //创建批次按钮
        $('#btnStart').on("click", function () { 
            if (!isNullOrWhiteSpaceStr($("#txtSubWorkflowInfo").textbox('getText'))) {
               var workflowName = $("#txtSubWorkflowInfo").textbox('getText').split(':')[0];
               var workflowRev = $("#txtSubWorkflowInfo").textbox('getText').split(':')[1];
                if(workflowRev !=$("#hdNewestSubWorkflowRev").val()){
                    $.messager.confirm({
                        title: '警告',
			            msg: '当前子工艺版本为：'+workflowRev+'，最新子工艺版本为：'+$("#hdNewestSubWorkflowRev").val()+'，是否继续开卡？？？',
			            ok: "开卡",
			            cancel: "取消",			  
			            fn : function(r){
                            if(r){			                
                                page.startContainer(false);                        
                            } 
			            }
                    });
                }else{
                    page.startContainer(false);   
                }
            }else{
                page.startContainer(false);  
            }
        });
        //创建批次并关闭按钮
        $('#btnStartAndClose').on("click", function () {
            if (!isNullOrWhiteSpaceStr($("#txtSubWorkflowInfo").textbox('getText'))) {
               var workflowName = $("#txtSubWorkflowInfo").textbox('getText').split(':')[0];
               var workflowRev = $("#txtSubWorkflowInfo").textbox('getText').split(':')[1];
                if(workflowRev !=$("#hdNewestSubWorkflowRev").val()){
                    $.messager.confirm({
                        title: '警告',
			            msg: '当前子工艺版本为：'+workflowRev+'，最新子工艺版本为：'+$("#hdNewestSubWorkflowRev").val()+'，是否继续开卡？？？',
			            ok: "开卡",
			            cancel: "取消",			  
			            fn : function(r){
                            if(r){			                
                                page.startContainer(true);                        
                            } 
			            }
                    });
                }else{
                    page.startContainer(true);   
                }
            }else{
                page.startContainer(true);  
            }
        });
        //大批次号更改事件
        $('#txtRbTogetherflag').textbox({
            onChange:function(n,o){
                page.getContainerNo2();
            }
        });
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();

    },
    //获取热表工艺 add by zhangrj
    getRBChildWorkflow:function(){
     var mainData = $("#gdMainContainer").datagrid('getData');
     $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: false,
            data: { action: "GetRBChildWorkflow", 
                workflowstepid: $('#ddlShipStep').combobox('getValue'),//下拉选择的转工序
                containerID:mainData.rows[0].CONTAINERID,
                containerType:mainData.rows[0].CONTAINERTYPE,
                subProductInfo:$("#hdSubProductInfo").val()
            },
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                var result = JSON.parse(data);
                if (result.Result) {
                    var returnData = result.ReturnData;
                    //子工艺
                    $("#txtSubWorkflowInfo").textbox('setValue', returnData.SubWorkflowId);
                    $("#txtSubWorkflowInfo").textbox('setText', returnData.SubWorkflowInfo);
                    //子工艺最新版本
                    $("#hdNewestSubWorkflowRev").val(returnData.NewestSubWorkflowRev);
                    //子件号
                    if (isNullOrWhiteSpaceStr(returnData.SubProductInfo)) {
                        var mainContainer = $("#gdMainContainer").datagrid("getRows");
                        $("#hdSubProductInfo").val(mainContainer[0].PRODUCTNAME + ":" + mainContainer[0].PRODUCTREV);
                    } else {
                        $("#hdSubProductInfo").val(returnData.SubProductInfo);
                    }
                    //子批次前部分
                    var prefix = "";
                    prefix = $("#hdSubProductInfo").val().split(':')[0] + "/"
                    $("#txtProductPrefix").textbox('setValue', prefix);
                    $("#txtProductPrefix").parent().attr("title",prefix);
                    //如果是子序号，更新子序号列表
                    if (mainData.rows[0].CONTAINERTYPE==="3") {
                        clearEasyuiDataGrid("gdChildContainer"); //清空列表
                        $("#gdChildContainer").datagrid('loadData', { rows: result.DBTable });
                    }
                    $("#txtStartDate").datebox('setValue',returnData.StepPlannedStartDate);
                } else {
                    displayMessage(result.Message, false);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                alert(XMLHttpRequest.responseText);
            }
        });
    },
    //获取批次号，大批次号和批次号一起更新
    getContainerNo: function () {
        //清除数据
        $("#hdRbRbTogetherflag").val('');
        $("#txtContainerNo").textbox('clear');

        var firstMainCon = $("#gdMainContainer").datagrid('getData').rows[0];
        var rbType = $('#ddlRbType').combobox('getValue');
        var date = new Date();
        var productPrefix = $("#txtProductPrefix").textbox('getValue');
        switch (rbType) {
            case "1":
                rbType = "R"
                break;
            case "2":
                rbType = "B"
                break;
            case "3":
                rbType = "T"
                break;
            default:
                break;
        }

        var rbTogetherflag = date.getFullYear().toString().substr(2)+ padStart((date.getMonth()+1).toString(),2,'0')+ "-" + rbType + "-";

        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: false,
            data: { action: "getNewestContainerNo", prefixInfo: productPrefix, rbTogetherflag: rbTogetherflag,
                subRbContainerType: $('#ddlRbType').combobox('getValue'),
                faTogetherFlag: firstMainCon.TOGATHERFLAG
            },
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                //prompt("", data);
                $.messager.progress('close');
                var result = JSON.parse(data);
                var returnData = result.ReturnData;
                if (result.Result) {
                    $("#txtContainerNo").textbox('setValue', returnData.RbContainerNo);
                    $("#hdRbRbTogetherflag").val(returnData.RbTogetherflag);
                    $("#txtRbTogetherflag").textbox('setValue', returnData.RbTogetherflag);
                    $("#hdRbRbTogetherflagType").val(returnData.RbTogetherflagType);
                } else {
                    displayMessage(result.Message, false);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                alert(XMLHttpRequest.responseText);
            }

        });
    },
    //获取批次号，只更新批次号
    getContainerNo2: function () {
       //清除数据
        $("#hdRbRbTogetherflag").val('');
        $("#txtContainerNo").textbox('clear');

        var productPrefix = $("#txtProductPrefix").textbox('getValue');
        var rbTogetherflag=$("#txtRbTogetherflag").textbox('getValue');

         $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: false,
            data: { action: "getNewestContainerNo2", prefixInfo: productPrefix, rbTogetherflag: rbTogetherflag},
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                //prompt("", data);
                $.messager.progress('close');
                var result = JSON.parse(data);
                var returnData = result.ReturnData;
                if (result.Result) {
                    $("#hdRbRbTogetherflag").val(rbTogetherflag);
                    $("#txtContainerNo").textbox('setValue', returnData);
                } else {
                    displayMessage(result.Message, false);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                alert(XMLHttpRequest.responseText);
            }

        });
    },
    //预览批次
    previewSubContainer: function () {
        clearEasyuiDataGrid('gdSubContainer2', 1);
        if (isNullOrWhiteSpaceStr($("#txtContainerNo").textbox('getValue'))) {
            displayMessage("没有批次号", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#txtStartDate").datebox('getValue'))) {
            displayMessage("请输入开始日期", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#txtEndDate").datebox('getValue'))) {
            displayMessage("请输入结束日期", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#dllWorkCenter").datebox('getValue'))) {
            displayMessage("请选择工区", false);
            return;
        }

        var container = $("#txtProductPrefix").textbox('getValue') + $("#txtContainerNo").textbox('getValue');
        var mainData = $("#gdMainContainer").datagrid('getData');
        //更新下大批次号
        page.getContainerNo();
        //如果是7需要更新最新的子卡序号
        var newestContainerName = '', togatherflag = $("#txtProductPrefix").textbox('getValue') + $("#txtContainerNo").textbox('getValue'); ;
        if (mainData.rows[0].CONTAINERTYPE == "7") {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                cashe: false,
                async: false,
                data: { action: "getNewestContainerNo", prefixInfo: togatherflag },
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //prompt("", data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    var returnData = result.ReturnData;
                    if (result.Result) {
                        newestContainerName = returnData.toString();
                    } else {
                        displayMessage(result.Message, false);
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }

            });
        } else {
            newestContainerName = togatherflag;
        }
        //赋值每个批次的数据
        var productName = $("#hdSubProductInfo").val().split(':')[0], productRevision = $("#hdSubProductInfo").val().split(':')[1];
        var workflowName = '', workflowRev = '';
        if (!isNullOrWhiteSpaceStr($("#txtSubWorkflowInfo").textbox('getText'))) {
            workflowName = $("#txtSubWorkflowInfo").textbox('getText').split(':')[0];
            workflowRev = $("#txtSubWorkflowInfo").textbox('getText').split(':')[1];
        }
        //prompt("", JSON.stringify(mainData.rows));
        var previewData = []; var index = 0;
        for (var i = 0; i < mainData.rows.length; i++) {
            var previewRow = { PLANNEDSTARTDATE: $("#txtStartDate").datebox('getValue'), PLANNEDCOMPLETIONDATE: $("#txtEndDate").datebox('getValue') };
            previewRow.TOGATHERFLAG = togatherflag; previewRow.FATHERCONTAINERID = mainData.rows[i].CONTAINERID;
            if (i == 0) {
                previewRow.CONTAINERNAME = newestContainerName;
            } else {
                index++;
                previewRow.CONTAINERNAME = togatherflag + padStart(parseInt(newestContainerName.replace(togatherflag, '')) + index, 3, '0');
            }
            previewRow.CONTAINERTYPE = mainData.rows[i].CONTAINERTYPE; previewRow.LEVEL = 'Lot';
            previewRow.PRODUCTNAME = productName; previewRow.PRODUCTREVISION = productRevision; previewRow.QTY = mainData.rows[i].QTY;
            previewRow.ISSELFMFG = mainData.rows[i].ISSELFMFG; previewRow.WORKFLOWNAME = workflowName; previewRow.WORKFLOWREVISION = workflowRev;
            previewRow.MFGORDERNAME = mainData.rows[i].MFGORDERNAME; previewRow.WORKCENTER = $("#dllWorkCenter").textbox('getText');
            previewRow.MFGWORKFLOWNAME = workflowName; previewRow.MFGWORKFLOWREVISION = workflowRev; previewRow.RBCONTAINERTYPE = $("#ddlRbType").textbox('getValue');
            previewRow.CONTAINERTYPENAME = "批量加工", previewRow.WORKFLOWINFO = $("#txtSubWorkflowInfo").textbox('getText');
            previewRow.WORKFLOWID = $("#txtSubWorkflowInfo").textbox('getValue');
            previewData.push(previewRow);
        }
        prompt("", JSON.stringify(previewData));
        $("#gdSubContainer2").datagrid('loadData', { rows: previewData });


    }
    //获取已经创建的热表批次
    , getCreatedRbContianer: function () {
        var mainData = $("#gdMainContainer").datagrid('getData');
        var ajaxParam = { action: "getCreatedRbContianer" };
        ajaxParam.containers = JSON.stringify(mainData.rows);

        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: true,
            data: ajaxParam,
            beforeSend: function () {
                $("#gdSubContainer").datagrid('loading');
            },
            success: function (data) {
                $("#gdSubContainer").datagrid('loaded');
                var result = JSON.parse(data);
                if (result.Result) {
                    $("#gdSubContainer").datagrid('loadData', { rows: result.DBTable });
                } else {
                    displayMessage("刷新热表批次失败:" + result.Message, false);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $("#gdSubContainer").datagrid('loaded');
                alert(XMLHttpRequest.responseText);
            }

        });

    }
    //批次创建
    , startContainer: function (isColse) {
        clearMessage();
        //验证
        if(new Date($("#txtEndDate").datebox('getValue').replace(/-/g,"/"))<new Date($("#txtStartDate").datebox('getValue').replace(/-/g,"/"))){
          displayMessage("结束日期不能早于开始日期", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#txtContainerNo").textbox('getValue'))) {
            displayMessage("没有批次号", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#txtStartDate").datebox('getValue'))) {
            displayMessage("请输入开始日期", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#txtEndDate").datebox('getValue'))) {
            displayMessage("请输入结束日期", false);
            return;
        }
        
        if (isNullOrWhiteSpaceStr($("#dllWorkCenter").datebox('getValue'))) {
            displayMessage("请选择工区", false);
            return;
        }
        if (isNullOrWhiteSpaceStr($("#ddlShipStep").datebox('getValue'))) {
            displayMessage("请选择转工工序", false);
            return;
        }
        var ajaxParam = { action: "startContainer" };
         //赋值每个批次的数据
        var mainData = $("#gdMainContainer").datagrid('getData');
        //验证子序号选择
        var childContainer=$("#gdChildContainer").datagrid('getChecked');
        if (mainData.rows[0].CONTAINERTYPE === "3"&&childContainer.length===0) {
            displayMessage("请选择子序号", false);
            return;
        }
        ajaxParam.childContainer = JSON.stringify(childContainer);

        //更新批次号
        page.getContainerNo2();//先暂时只更新containername,后续可能需要用page.getContainerNo()
        //获取containers

       

        var workflowName = '', workflowRev = '', productName = '', productRevision = '', newestContainerName = $("#txtContainerNo").textbox('getValue');
        if (!isNullOrWhiteSpaceStr($("#hdSubProductInfo").val())) {
            productName = $("#hdSubProductInfo").val().split(':')[0];
            productRevision = $("#hdSubProductInfo").val().split(':')[1];
            newestContainerName = $("#txtProductPrefix").textbox('getValue') + newestContainerName;
        }
        if (!isNullOrWhiteSpaceStr($("#txtSubWorkflowInfo").textbox('getText'))) {
            workflowName = $("#txtSubWorkflowInfo").textbox('getText').split(':')[0];
            workflowRev = $("#txtSubWorkflowInfo").textbox('getText').split(':')[1];
        }
        //热表无子工艺情况下先默认工艺
        if (isNullOrWhiteSpaceStr(workflowName)) {
            //workflowName = "WF-热表默认工艺"; workflowRev = "1";
            displayMessage("热表无子工艺，请检查工艺信息", false);
            return;
        }

        //prompt("", JSON.stringify(mainData.rows));
        var previewData = []; var index = 0;
        for (var i = 0; i < mainData.rows.length; i++) {
            var previewRow = { PLANNEDSTARTDATE: $("#txtStartDate").datebox('getValue'), PLANNEDCOMPLETIONDATE: $("#txtEndDate").datebox('getValue'),IsTimeEffective: $("#dllIsTimeEffective").combobox('getValue')};
            previewRow.TOGATHERFLAG = newestContainerName; previewRow.CONTAINERNAME = newestContainerName;
            previewRow.CONTAINERTYPE = mainData.rows[0].CONTAINERTYPE; previewRow.LEVEL = 'Lot'; previewRow.PRODUCTNAME = productName; previewRow.PRODUCTREVISION = productRevision;

            if (mainData.rows[0].CONTAINERTYPE == "7") {
                previewRow.QTY = mainData.rows.length;
            } else {
                previewRow.QTY = mainData.rows[i].QTY;
            }
            previewRow.CONTAINERNO = $("#txtContainerNo").textbox("getValue");previewRow.RbTogetherflagType = $("#hdRbRbTogetherflagType").val();
            previewRow.ISSELFMFG = mainData.rows[i].ISSELFMFG; previewRow.WORKFLOWNAME = workflowName; previewRow.WORKFLOWREVISION = workflowRev;
            previewRow.MFGORDERNAME = mainData.rows[i].MFGORDERNAME; previewRow.WORKCENTER = $("#dllWorkCenter").textbox('getText');
            previewRow.MFGWORKFLOWNAME = workflowName; previewRow.MFGWORKFLOWREVISION = workflowRev; previewRow.RBCONTAINERTYPE = $("#ddlRbType").textbox('getValue');
            previewRow.CONTAINERTYPENAME = mainData.rows[0].CONTAINERTYPENAME, previewRow.WORKFLOWINFO = $("#txtSubWorkflowInfo").textbox('getText');
            previewRow.WORKFLOWID = $("#txtSubWorkflowInfo").textbox('getValue'); previewRow.RBTOGETHERFLAG = $("#hdRbRbTogetherflag").val();
            //父卡信息
            previewRow.FATHERCONTAINERID = mainData.rows[i].CONTAINERID; previewRow.FAQTY = mainData.rows[i].QTY; previewRow.FAWORKFLOWSTEPID = $("#ddlShipStep").datebox('getValue');
            previewRow.FATOGATHERFLAG=mainData.rows[i].TOGATHERFLAG;previewRow.FAWORKFLOWSTEPNAME=$("#ddlShipStep").datebox('getText');
            previewData.push(previewRow);
        }

        ajaxParam.containers = JSON.stringify(previewData);

        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            cashe: false,
            async: true,
            data: ajaxParam,
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
                //console.log(new Date());
            },
            success: function (data) {
                //prompt("", data);
                $.messager.progress('close');
                //console.log(new Date());
                var result = JSON.parse(data);
                if (result.Result) {
                    displayMessage("批次创建成功", true);
                    //刷新一些数据
                    page.getCreatedRbContianer();
                    page.getContainerNo();
                    $("#dllWorkCenter").textbox('clear');
                    $("#txtStartDate").datebox('setValue', '');
                    $("#txtEndDate").datebox('setValue', '');
                    //关闭窗口
                    if (isColse == true) {
                        window.close();
                    }

                } else {
                    displayMessage(result.Message, false);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                alert(XMLHttpRequest.responseText);
            }

        });

    }
}
$(function () {
    page.init();
});